package icu.qx.gbs.service.impl;

import java.util.List;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import icu.qx.common.constant.TableNameEnum;
import icu.qx.common.utils.CodeUtils;
import icu.qx.gbs.domain.GbsGood;
import icu.qx.gbs.mapper.GbsGoodMapper;
import icu.qx.gbs.service.IGbsGoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 物品 通过 is_material 区分物料和产品Service业务层处理
 *
 * @author yong
 * @date 2024-06-06
 */
@Service
public class GbsGoodServiceImpl implements IGbsGoodService {
    @Autowired
    private GbsGoodMapper gbsGoodMapper;

    /**
     * 查询物品 通过 is_material 区分物料和产品
     *
     * @param pdCode 物品 通过 is_material 区分物料和产品主键
     * @return 物品 通过 is_material 区分物料和产品
     */
    @Override
    public GbsGood selectGbsGoodByPdCode(String pdCode) {
        return gbsGoodMapper.selectGbsGoodByPdCode(pdCode);
    }

    @Override
    public List<GbsGood> selectGbsGoodByRouteCode(String routeCode) {
        return gbsGoodMapper.selectGbsGoodByRouteCode(routeCode);
    }

    @Override
    public List<GbsGood> selectGbsGoodNoRoute() {
        return gbsGoodMapper.selectGbsGoodNoRoute();
    }

    @Override
    public List<GbsGood> selectGbsGoodListByPdCode(String[] pdCodes) {
        return gbsGoodMapper.selectGbsGoodListByPdCode(pdCodes);
    }

    /**
     * 查询物品 通过 is_material 区分物料和产品列表
     *
     * @param gbsGood 物品 通过 is_material 区分物料和产品
     * @return 物品 通过 is_material 区分物料和产品
     */
    @Override
    public List<GbsGood> selectGbsGoodList(GbsGood gbsGood) {
        return gbsGoodMapper.selectGbsGoodList(gbsGood);
    }

    /**
     * 新增物品 通过 is_material 区分物料和产品
     *
     * @param gbsGood 物品 通过 is_material 区分物料和产品
     * @return 结果
     */
    @Override
    public GbsGood insertGbsGood(GbsGood gbsGood) {
        gbsGood.setCreateBy(SecurityUtils.getUsername());
        gbsGood.setCreateTime(DateUtils.getNowDate());
        gbsGoodMapper.insertGbsGood(gbsGood);
        return gbsGood;
    }

    /**
     * 修改物品 通过 is_material 区分物料和产品
     *
     * @param gbsGood 物品 通过 is_material 区分物料和产品
     * @return 结果
     */
    @Override
    public GbsGood updateGbsGood(GbsGood gbsGood) {
        gbsGood.setUpdateBy(SecurityUtils.getUsername());
        gbsGood.setUpdateTime(DateUtils.getNowDate());
        gbsGoodMapper.updateGbsGood(gbsGood);
        return gbsGood;
    }

    @Transactional(rollbackFor = {Exception.class, RuntimeException.class})
    @Override
    public int updateGbsGoodRoute(List<GbsGood> gbsGoods) {
        gbsGoods.forEach(e -> {
            gbsGoodMapper.updateGbsGoodRoute(e);
        });
        return 1;
    }

    /**
     * 批量删除物品 通过 is_material 区分物料和产品
     *
     * @param pdCodes 需要删除的物品 通过 is_material 区分物料和产品主键
     * @return 结果
     */
    @Override
    public int deleteGbsGoodByPdCodes(String[] pdCodes) {
        return gbsGoodMapper.deleteGbsGoodByPdCodes(pdCodes);
    }

    /**
     * 删除物品 通过 is_material 区分物料和产品信息
     *
     * @param pdCode 物品 通过 is_material 区分物料和产品主键
     * @return 结果
     */
    @Override
    public int deleteGbsGoodByPdCode(String pdCode) {
        return gbsGoodMapper.deleteGbsGoodByPdCode(pdCode);
    }
}
